package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DzTiku;
import com.ruoyi.system.service.IDzTikuService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 题库信息Controller
 * 
 * @author ruoyi
 * @date 2022-09-02
 */
@RestController
@RequestMapping("/system/tiku")
public class DzTikuController extends BaseController
{
    @Autowired
    private IDzTikuService dzTikuService;

    /**
     * 查询题库信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:tiku:list')")
    @GetMapping("/list")
    public TableDataInfo list(DzTiku dzTiku)
    {
        startPage();
        List<DzTiku> list = dzTikuService.selectDzTikuList(dzTiku);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('system:tiku:list')")
    @GetMapping("/list2")
    public TableDataInfo list2(DzTiku dzTiku)
    {
        startPage();
        List<DzTiku> list = dzTikuService.selectDzShiList(dzTiku);
        return getDataTable(list);
    }

    /**
     * 导出题库信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:tiku:export')")
    @Log(title = "题库信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzTiku dzTiku)
    {
        List<DzTiku> list = dzTikuService.selectDzTikuList(dzTiku);
        ExcelUtil<DzTiku> util = new ExcelUtil<DzTiku>(DzTiku.class);
        util.exportExcel(response, list, "题库信息数据");
    }

    /**
     * 获取题库信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:tiku:query')")
    @GetMapping(value = "/{tiId}")
    public AjaxResult getInfo(@PathVariable("tiId") Long tiId)
    {
        return AjaxResult.success(dzTikuService.selectDzTikuByTiId(tiId));
    }

    /**
     * 新增题库信息
     */
    @PreAuthorize("@ss.hasPermi('system:tiku:add')")
    @Log(title = "题库信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzTiku dzTiku)
    {
        return toAjax(dzTikuService.insertDzTiku(dzTiku));
    }

    @PreAuthorize("@ss.hasPermi('system:tiku:add')")
    @Log(title = "随机组题", businessType = BusinessType.INSERT)
    @PostMapping("/addList")
    public AjaxResult addList(@RequestBody List<DzTiku>  dzTikuList)
    {
        return toAjax(dzTikuService.insertDzTikuList(dzTikuList));
    }

    /**
     * 修改题库信息
     */
    @PreAuthorize("@ss.hasPermi('system:tiku:edit')")
    @Log(title = "题库信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzTiku dzTiku)
    {
        return toAjax(dzTikuService.updateDzTiku(dzTiku));
    }

    /**
     * 删除题库信息
     */
    @PreAuthorize("@ss.hasPermi('system:tiku:remove')")
    @Log(title = "题库信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tiIds}")
    public AjaxResult remove(@PathVariable Long[] tiIds)
    {
        return toAjax(dzTikuService.deleteDzTikuByTiIds(tiIds));
    }
}
